using System.Text;

namespace Engine.FileFormats3D.C11Syndikat.QADFile
{
    public class SurfaceChunk
    {
        #region Public Fields

        public ushort bump;
        public uint numberOfPolygons;
        public uint startPolygon;
        public ushort surface;

        #endregion Public Fields

        #region Public Constructors

        public SurfaceChunk(uint startPolygon, ushort surface, ushort bump, uint numberOfPolygons)
        {
            this.startPolygon = startPolygon;
            this.surface = surface;
            this.bump = bump;
            this.numberOfPolygons = numberOfPolygons;
        }

        #endregion Public Constructors

        #region Public Methods

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(" Surface Chunk" + " ");
            sb.AppendLine(" startPolygon:     " + this.startPolygon.ToString() + " ");
            sb.AppendLine(" SurfaceID :       " + this.surface.ToString() + " ");
            sb.AppendLine(" Bump :       " + this.bump.ToString() + " ");
            sb.AppendLine(" numberOfPolygons: " + this.numberOfPolygons.ToString() + " ");
            sb.AppendLine(" ==== End of Surface Chunk ======");
            return sb.ToString();
        }

        #endregion Public Methods

        #region Internal Methods

        internal static SurfaceChunk FromStream(System.IO.BinaryReader br)
        {
            uint startPolygon = br.ReadUInt32();
            uint numberOfPolygons = br.ReadUInt32();
            ushort surface = br.ReadUInt16();
            ushort bump = br.ReadUInt16();

            return new SurfaceChunk(startPolygon, surface, bump, numberOfPolygons);
        }

        internal void Save(System.IO.BinaryWriter bw)
        {
            bw.Write(this.startPolygon);
            bw.Write(this.numberOfPolygons);
            bw.Write(this.surface);
        }

        #endregion Internal Methods
    }
}